package io.renren.modules.eas.service.impl;

import io.renren.modules.eas.entity.EasBasicStuEntity;
import io.renren.modules.eas.service.EasBasicStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.eas.dao.EasStuCommentsDao;
import io.renren.modules.eas.entity.EasStuCommentsEntity;
import io.renren.modules.eas.service.EasStuCommentsService;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;


@Service("easStuCommentsService")
public class EasStuCommentsServiceImpl extends ServiceImpl<EasStuCommentsDao, EasStuCommentsEntity> implements EasStuCommentsService {

    @Autowired
    private EasBasicStuService basicStuService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<EasStuCommentsEntity> page = this.page(
                new Query<EasStuCommentsEntity>().getPage(params),
                new QueryWrapper<EasStuCommentsEntity>()
                        .eq(!ObjectUtils.isEmpty(params.get("edu1Num")),"edu1_num",params.get("edu1Num"))
                        .eq(!ObjectUtils.isEmpty(params.get("edu2Num")),"edu2_num",params.get("edu2Num"))
                        .eq(!ObjectUtils.isEmpty(params.get("edu3Num")),"edu3_num",params.get("edu3Num"))
                        .eq(!ObjectUtils.isEmpty(params.get("edu4Num")),"edu4_num",params.get("edu4Num"))
                        .eq(!ObjectUtils.isEmpty(params.get("edu5Num")),"edu5_num",params.get("edu5Num"))
                        .eq(!ObjectUtils.isEmpty(params.get("commentNum")),"comment_num",params.get("commentNum"))
                        .eq(!ObjectUtils.isEmpty(params.get("keywordsNum")),"keywords_num",params.get("keywordsNum"))
                        .eq(!ObjectUtils.isEmpty(params.get("academicYear")),"academic_year",params.get("academicYear"))
                        .eq(!ObjectUtils.isEmpty(params.get("semester")),"semester",params.get("semester"))
                        .eq(!ObjectUtils.isEmpty(params.get("classId")),"class_id",params.get("classId"))
        );
        for (EasStuCommentsEntity record : page.getRecords()) {
            EasBasicStuEntity one = basicStuService.lambdaQuery().eq(EasBasicStuEntity::getId, record.getStudentId()).one();
            if (!ObjectUtils.isEmpty(one)) {
                record.setName(one.getName());
            }
        }
        return new PageUtils(page);
    }

}
